#include "ProcessPool.hpp"
#include <ctime>

int main(){
    try{
        //制定随机数种子
        srand((unsigned)time(nullptr));

        //准备任务列表
        std::vector<Task> Tasks;
        LoadTasks(Tasks); 

        //初始化对象
        ProcessPool processpool(10, Tasks);
        std::cout << "ProcesPool is OK" << std::endl;
        
        int Tasks_Number = 20;
        //派送任务
        for(int i = 0; i < Tasks_Number; i++){
            //获取任务索引
            int taskId = rand() % Tasks.size(); 
            std::cout << "[Master] Submitting Task " << taskId << "..." << std::endl;
            //master发送任务
            processpool.SubmitTask(taskId);
            //延迟1秒
            sleep(1);
        }

        std::cout << "[Master] All Tasks Submitted. Shutting Down The Pool..." << std::endl;

    }catch(const std::exception& e){
        std::cerr << "Error:" << e.what() << std::endl;
        return 1;
    }
    return 0;
}